<template>
  <div>
    <el-card>
      <!--查询条件start --111s-->
      <el-form :inline="true" :model="query" class="query-form" size="small">
        <el-form-item>
          <span>商品分类：</span>
          <el-select
            v-model="query.thirdcategoryid"
            placeholder="请选择"
            @change="thirdchange(1)"
            clearable
          >
            <el-option
              v-for="item in busCommodityThirdCategoryList"
              :key="item.topcategoryid"
              :label="item.topcategoryname"
              :value="item.topcategoryid"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item class="query-form-item">
          <el-input
            v-model="query.content"
            placeholder="请输入商品名"
            prefix-icon="el-icon-search"
            @keyup.enter.native="onSubmit"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-refresh"
            @click="onRest"
          ></el-button>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit"
            >查询</el-button
          >
          <el-button
            type="primary"
            icon="el-icon-edit"
            @click.native="handleForm()"
            >添加</el-button
          >
        </el-form-item>
      </el-form>
      <!--列表start --222s-->
      <el-table
        ref="multipleTable"
        v-loading="loading"
        :data="list"
        :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
        @selection-change="handleSelectionChange"
        border
      >
        <el-table-column type="selection" width="50" fixed />
        <el-table-column
          label="商品ID"
          prop="commodityid"
          width="50"
          align="center"
        />

        <el-table-column
          label="商品图片"
          prop="commodityicon"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <el-popover
              v-if="scope.row.commodityicon"
              placement="right"
              trigger="hover"
            >
              <img
                :src="scope.row.commodityicon"
                style="width: 400px; border-radius: 3px"
              />
              <img
                slot="reference"
                :src="scope.row.commodityicon"
                style="max-height: 80px; max-width: 50px; border-radius: 5px"
              />
            </el-popover>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="商品名称" prop="commodityname" align="center" />
        <el-table-column
          label="一级分类"
          prop="topcategoryname"
          width="150"
          align="center"
        />
        <el-table-column
          label="二级分类"
          prop="secondarycategoryname"
          width="150"
          align="center"
        />
        <el-table-column
          label="三级分类"
          prop="thirdcategoryname"
          width="150"
          align="center"
        />
        <el-table-column label="审核状态" width="100" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.commoditystatus == 0">审核中</el-tag>
            <el-tag v-if="scope.row.commoditystatus == 1">审核通过</el-tag>
            <el-tag v-if="scope.row.commoditystatus == 2">审核拒绝</el-tag>
            <div v-if="scope.row.commoditystatus == 2">
              <el-button type="text" @click="openAlert(scope.row)"
                >查看</el-button
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="库存"
          prop="commoditynum"
          width="150"
          align="center"
        />
        <!-- <el-table-column label="上架状态" prop="onshelfstatus" align="center" width="100">
                <template slot-scope="scope">
                    <el-switch
                        :disabled="scope.row.commoditystatus !==1? true:false  "
                        v-model="scope.row.onshelfstatus"
                        active-color="#13ce66"
                        inactive-color="#ff4949"
                        active-value='1'
                        inactive-value='0'
                        @change="onshelfschange(scope.row)"
                    >
                    </el-switch>
                </template>
            </el-table-column> -->
        <el-table-column
          label="上架"
          prop="onshelfstatus"
          align="center"
          width="120"
        >
          <template slot-scope="scope">
            <el-switch
              :disabled="scope.row.commoditystatus !== 1 ? true : false"
              class="switch"
              v-model="scope.row.onshelfstatus"
              active-color="#13ce66"
              inactive-color="#ff4949"
              active-text="上架"
              inactive-text="下架"
              :active-value="1"
              :inactive-value="0"
              @change="onshelfschange(scope.row)"
              style="margin-left: 6px"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column
          label="添加时间"
          with="280"
          :show-overflow-tooltip="true"
          align="center"
        >
          <template slot-scope="scope">
            <i class="el-icon-time" v-if="scope.row.createtime != null"></i>
            <span v-if="scope.row.createtime != null">{{
              scope.row.createtime | formatDateStr("yyyy-MM-dd hh:mm:ss")
            }}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" align="center" width="300" fixed="right">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click.native="detailForm(scope.$index, scope.row)"
              >查看
            </el-button>
            <el-button
              type="primary"
              size="mini"
              @click.native="editForm(scope.$index, scope.row)"
              >编辑
            </el-button>
            <el-button
              type="primary"
              size="mini"
              @click.native="editInventoryForm(scope.$index, scope.row)"
              >库存
            </el-button>
            <el-button
              type="danger"
              size="mini"
              @click.native="handleDel(scope.row.commodityid)"
              >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--列表end --222e-->
      <div class="left-container">
        <el-button type="danger" size="small" @click="delGroup()"
          >删除已选</el-button
        >
        <!-- <transition name="el-fade-in-linear">
                <el-button size="small" @click="toggleSelection()" v-show="cancelToggle"
                >取消选择</el-button
                >
            </transition> -->
      </div>
      <!--分页模块start-->
      <el-pagination
        class="pagination-container"
        background
        :page-size="query.pageSize"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next, jumper"
        :current-page="query.currentPage"
        :page-sizes="[5, 10, 20, 30, 50]"
        :total="totalNumber"
      ></el-pagination>
      <!--分页模块end-->

      <!--查看弹框-->
      <el-dialog
        title="查看"
        :visible.sync="detailVisible"
        :before-close="hideDetailForm"
        width="50%"
        top="5vh"
        v-dialogDrag
        :close-on-click-modal="false"
      >
        <template slot="title">
          <div class="avue-crud__dialog__header">
            <span class="el-dialog__title">
              <span
                style="
                  display: inline-block;
                  background-color: #3478f5;
                  width: 3px;
                  height: 20px;
                  margin-right: 5px;
                  float: left;
                  margin-top: 2px;
                "
              ></span>
              查看
            </span>
            <div class="avue-crud__dialog__menu">
              <icon-svg icon-class="quanping" />
              <span class="mention">双击全屏</span>
            </div>
          </div>
        </template>
        <el-card>
          <el-form :model="formData" label-width="140px">
            <el-form-item
              label-width="80px"
              label="资质审核"
              style="background: #e1e1e1"
            >
            </el-form-item>
            <Table
              border
              :tableData="certificationAuditData"
              :tableOptions="certificationAuditOptions"
            >
            </Table>
            <el-form-item
              label-width="80px"
              label="商品审核"
              style="background: #e1e1e1; margin-top: 30px"
            >
            </el-form-item>
            <Table
              border
              :tableData="goodsAuditData"
              :tableOptions="goodsAuditOptions"
            >
            </Table>

            <el-form-item
              label-width="80px"
              label="基本参数"
              style="background: #e1e1e1; margin-top: 30px"
            >
            </el-form-item>
            <el-form-item
              style="border-bottom: 1px solid #ebeef5"
              label-width="0px"
            >
              <el-form-item
                label="商品名称:"
                style="width: 30%; display: inline-block"
              >
                <span>{{ formData.commodityname }}</span>
              </el-form-item>
              <el-form-item
                label="商品分类:"
                style="margin-left: 80px; width: 50%; display: inline-block"
              >
                <span>{{
                  formData.topcategoryname +
                  "," +
                  formData.secondarycategoryname +
                  "," +
                  formData.thirdcategoryname
                }}</span>
              </el-form-item>
            </el-form-item>

            <el-form-item
              style="border-bottom: 1px solid #ebeef5"
              label-width="0px"
            >
              <el-form-item
                label="经销价:"
                style="width: 30%; display: inline-block"
              >
                <input
                  v-model="formData.commodityoldprice"
                  type="text"
                  readonly
                />
              </el-form-item>
              <el-form-item
                label="零售价:"
                style="margin-left: 80px; width: 30%; display: inline-block"
              >
                <input v-model="formData.commodityprice" type="text" readonly />
              </el-form-item>
            </el-form-item>

            <el-form-item
              style="border-bottom: 1px solid #ebeef5"
              label-width="0px"
            >
              <el-form-item
                label="添加时间:"
                style="width: 30%; display: inline-block"
              >
                <input
                  :value="formData.createtime | formatDateStr('yyyy-MM-dd')"
                  type="text"
                  readonly
                />
              </el-form-item>
              <el-form-item
                label="商品ID:"
                style="margin-left: 80px; width: 30%; display: inline-block"
              >
                <input v-model="formData.commodityid" type="text" readonly />
              </el-form-item>
            </el-form-item>
            <el-form-item
              style="border-bottom: 1px solid #ebeef5"
              label-width="0px"
            >
              <el-form-item
                label="封面图:"
                style="width: 30%; display: inline-block"
              >
                <el-popover
                  v-if="formData.commodityicon"
                  placement="right"
                  trigger="hover"
                >
                  <img
                    :src="formData.commodityicon"
                    style="width: 400px; border-radius: 3px"
                  />
                  <img
                    slot="reference"
                    :src="formData.commodityicon"
                    style="
                      max-height: 80px;
                      max-width: 50px;
                      border-radius: 5px;
                    "
                  />
                </el-popover>
                <span v-else>-</span>
              </el-form-item>
              <el-form-item
                label="库存:"
                style="margin-left: 70px; width: 30%; display: inline-block"
              >
                <input v-model="formData.commoditynum" type="text" readonly />
              </el-form-item>
            </el-form-item>
            <el-form-item
              style="border-bottom: 1px solid #ebeef5; padding-bottom: 10px"
              label-width="0px"
            >
              <el-form-item
                label="商品评论:"
                style="width: 30%; display: inline-block"
              >
                <el-button @click="lookcomment(formData.commodityid)"
                  >查看</el-button
                >
              </el-form-item>
              <!-- <el-form-item label="上架:" style="margin-left:80px; width:30%;display: inline-block;">
                        <div>
                            <el-switch
                                v-model="formData.onshelfstatus"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                active-value='2'
                                inactive-value='1'
                                @change="onshelfschange(formData)"
                            >
                            </el-switch>
                        </div>

                    </el-form-item> -->
            </el-form-item>
            <!-- 商品属性-->
            <el-form-item
              label-width="80px"
              label="商品属性"
              style="background: #e1e1e1"
            />
            <span v-if="attributecontenct != [] && attributecontenct != null">
              <h3 style="height: 50px; margin-left: 40px" class="thrTitle">
                基本属性
              </h3>
              <div
                :prop="'fieldname' + index"
                v-for="(item, index) in attributecontenct"
                :key="item.id"
              >
                <el-form-item
                  label-width="180px"
                  :label="item.fieldname + '：'"
                >
                  <el-input
                    v-model.trim="formData1[item.fieldname]"
                    v-if="item.fieldtype == '文字'"
                    type="text"
                    :disabled="true"
                    maxlength="10"
                    :placeholder="'请填写' + item.fieldname"
                  ></el-input>
                  <el-input
                    v-model.trim="formData1[item.fieldname]"
                    v-if="item.fieldtype == '数字'"
                    :disabled="true"
                    type="number"
                    oninput="if(value.length>10)value=value.slice(0,10)"
                    min="0"
                    :placeholder="'请填写' + item.fieldname"
                  ></el-input>
                </el-form-item>
              </div>
            </span>

            <span
              v-if="
                attributeextendcontenct != [] && attributeextendcontenct != null
              "
            >
              <h3 style="height: 50px; margin-left: 40px" class="thrTitle">
                扩展属性
              </h3>
              <div
                :prop="'extendfieldname' + index"
                v-for="(item, index) in attributeextendcontenct"
                :key="item.id"
              >
                <el-form-item
                  label-width="180px"
                  :label="item.extendfieldname + '：'"
                >
                  <el-input
                    v-model.trim="formData1[item.extendfieldname]"
                    v-if="item.fieldtype == '文字'"
                    :disabled="true"
                    type="text"
                    maxlength="10"
                    :placeholder="'请填写' + item.extendfieldname"
                  ></el-input>
                  <el-input
                    v-model.trim="formData1[item.extendfieldname]"
                    v-if="item.fieldtype == '数字'"
                    :disabled="true"
                    type="number"
                    oninput="if(value.length>10)value=value.slice(0,10)"
                    :min="0"
                    :placeholder="'请填写' + item.extendfieldname"
                  ></el-input>
                </el-form-item>
              </div>
            </span>
            <!--资质认证-->
            <el-form-item
              label-width="110px"
              label="商品资质认证"
              style="background: #e1e1e1"
            >
            </el-form-item>
            <span v-if="categoryTemplate != [] && categoryTemplate != null">
              <h3 style="height: 50px; margin-left: 40px" class="thrTitle">
                {{ categoryTemplate.name || "" }}
              </h3>
              <el-form-item
                label-width="180px"
                :label="item.fieldname + '：'"
                :prop="'fieldname' + index"
                v-for="(item, index) in categoryTemplate.templateItemFormList"
                :key="item.id"
              >
                <input type="hidden" v-model="item.fieldvalue" />
                <el-input
                  v-model="formData4[item.fieldname]"
                  @input="onInput()"
                  @change="changeInput(item)"
                  v-if="item.fieldtype == '文字'"
                  type="text"
                  :disabled="true"
                  :placeholder="'请填写' + item.fieldname"
                ></el-input>
                <el-input
                  v-model="formData4[item.fieldname]"
                  @input="onInput()"
                  @change="changeInput(item)"
                  v-if="item.fieldtype == '数字'"
                  type="number"
                  :disabled="true"
                  :placeholder="'请填写' + item.fieldname"
                ></el-input>

                <el-popover
                  v-if="item.fieldtype == '图片'"
                  placement="right"
                  trigger="hover"
                >
                  <img
                    :src="item.fieldvalue"
                    style="width: 400px; border-radius: 3px"
                  />
                  <img
                    slot="reference"
                    :src="item.fieldvalue"
                    style="
                      max-height: 80px;
                      max-width: 150px;
                      border-radius: 5px;
                    "
                  />
                </el-popover>
              </el-form-item>
            </span>
            <el-form-item
              label-width="80px"
              label="规格参数"
              style="background: #e1e1e1"
            >
            </el-form-item>
            <el-table
              style="margin-bottom: 20px"
              ref="multipleTable"
              v-loading="loading"
              :data="parameterlist"
              :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
              @selection-change="handleSelectionChange"
              border
            >
              <el-table-column label="商品图片" width="100" align="center">
                <template slot-scope="scope">
                  <el-popover
                    v-if="scope.row.inventorypic"
                    placement="right"
                    trigger="hover"
                  >
                    <img
                      :src="scope.row.inventorypic"
                      style="width: 400px; border-radius: 3px"
                    />
                    <img
                      slot="reference"
                      :src="scope.row.inventorypic"
                      style="
                        max-height: 80px;
                        max-width: 50px;
                        border-radius: 5px;
                      "
                    />
                  </el-popover>
                  <span v-else>-</span>
                </template>
              </el-table-column>
              <el-table-column label="规格参数" align="center">
                <el-table-column
                  v-for="(item, index) in inputData"
                  :key="index"
                  :label="item.key"
                  width="150"
                  align="center"
                >
                  <template slot-scope="scope">
                    <div v-if="scope.row.splist !== undefined">
                      <el-select
                        v-model="scope.row.splist[index]"
                        placeholder="请选择"
                        disabled
                        ref="sel"
                      >
                        <el-option
                          v-for="(it, ind) in item.val.split(',')"
                          :key="ind"
                          :label="it"
                          :value="it"
                        >
                        </el-option>
                      </el-select>
                    </div>
                  </template>
                </el-table-column>
              </el-table-column>
              <el-table-column label="成本价" prop="costprice" align="center" />
              <el-table-column
                label="经销价"
                prop="secondaryagentprice"
                align="center"
              />
              <el-table-column
                label="分销价"
                prop="commodityprice"
                align="center"
              />
              <el-table-column
                label="零售价"
                prop="commodityoldprice"
                align="center"
              />
              <el-table-column
                label="推广比例(%)"
                prop="profitproportion"
                width="150"
                align="center"
              >
                <template slot-scope="scope">
                  <el-input-number
                    style="width: 120px"
                    v-model="scope.row.profitproportion"
                    align="center"
                    disabled
                    :min="0"
                    :controls="false"
                    :precision="4"
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                label="库存"
                prop="inventorynum"
                align="center"
              />
            </el-table>
            <el-form-item
              label-width="65px"
              label="轮播图"
              style="background: #e1e1e1; margin-top: 20px"
            >
            </el-form-item>
            <el-form-item>
              <div
                v-for="(item, index) in formData.commoditypiclist"
                :key="index"
                style="display: inline-block"
              >
                <img
                  :src="item"
                  style="width: 200px; border-radius: 3px; margin-left: 5px"
                />
              </div>
            </el-form-item>

            <el-form-item
              label-width="80px"
              label="商品详情"
              style="background: #e1e1e1"
            ></el-form-item>

            <span
              v-html="formData.commoditydesc"
              style="margin-left: 10%; display: block"
            ></span>
          </el-form>
        </el-card>
      </el-dialog>

      <!--add新建编辑-->
      <el-dialog
        :title="formMap[formName]"
        :visible.sync="formVisible"
        :before-close="hideForm"
        width="50%"
        top="5vh"
        v-dialogDrag
        :close-on-click-modal="false"
      >
        <template slot="title">
          <div class="avue-crud__dialog__header">
            <span class="el-dialog__title">
              <span
                style="
                  display: inline-block;
                  background-color: #3478f5;
                  width: 3px;
                  height: 20px;
                  margin-right: 5px;
                  float: left;
                  margin-top: 2px;
                "
              ></span>
              {{ formMap[formName] }}
            </span>
            <div class="avue-crud__dialog__menu">
              <icon-svg icon-class="quanping" />
              <span class="mention">双击全屏</span>
            </div>
          </div>
        </template>
        <el-card>
          <el-form :model="formData" :rules="formRules" ref="ruleForm">
            <el-form-item
              label-width="80px"
              label="基本参数"
              style="background: #e1e1e1"
            >
            </el-form-item>
            <el-form-item
              label-width="120px"
              label="商品名称："
              prop="commodityname"
            >
              <el-input
                style="width: 60%"
                v-model="formData.commodityname"
                placeholder="请输入商品名称"
                clearable
              ></el-input>
            </el-form-item>
            <el-form-item
              label-width="120px"
              label="商品分类："
              prop="thirdcategoryid"
            >
              <span style="margin-right: 10px"
                >{{
                  oneCategoryObj.topcategoryname +
                  " --> " +
                  twoCategoryObj.topcategoryname +
                  " --> "
                }}
              </span>
              <el-select
                v-model="formData.thirdcategoryid"
                placeholder="请选择"
                clearable
                @change="thirdchange(2)"
              >
                <!-- :disabled="formData.commodityid != ''" -->
                <el-option
                  v-for="item in busCommodityThirdCategoryList"
                  :key="item.topcategoryid"
                  :label="item.topcategoryname"
                  :value="item.topcategoryid"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <!-- 商品属性-->

            <el-form-item
              label-width="80px"
              label="商品属性"
              style="background: #e1e1e1"
              v-show="categoryTemplateShow"
            />
            <el-form :model="formData1" :rules="form1Rules" ref="formData1">
              <span v-if="attributecontenct != [] && attributecontenct != null">
                <h3
                  style="height: 50px; margin-left: 40px"
                  class="thrTitle"
                  v-show="categoryTemplateShow"
                >
                  基本属性
                </h3>

                <div v-for="(item, index) in attributecontenct" :key="item.id">
                  <el-form-item
                    :prop="item.fieldname"
                    label-width="180px"
                    :label="item.fieldname + '：'"
                  >
                    <el-input
                      v-model.trim="formData1[item.fieldname]"
                      @input="onInput1()"
                      @change="changeInput1(item)"
                      v-if="item.fieldtype == '文字'"
                      type="text"
                      maxlength="10"
                      :placeholder="'请填写' + item.fieldname"
                    ></el-input>
                    <el-input
                      v-model.trim="formData1[item.fieldname]"
                      @input="onInput1()"
                      @change="changeInput1(item)"
                      v-if="item.fieldtype == '数字'"
                      type="number"
                      oninput="value=value.replace(/[^\d]/g,'').slice(0,10)"
                      :min="0"
                      :placeholder="'请填写' + item.fieldname + '（数字类型）'"
                    ></el-input>
                  </el-form-item>
                </div>
              </span>

              <span
                v-if="
                  attributeextendcontenct != [] &&
                  attributeextendcontenct != null
                "
              >
                <h3
                  style="height: 50px; margin-left: 40px"
                  class="thrTitle"
                  v-show="categoryTemplateShow"
                >
                  扩展属性
                </h3>
                <div
                  v-for="(item, index) in attributeextendcontenct"
                  :key="item.id"
                >
                  <el-form-item
                    :prop="item.extendfieldname"
                    label-width="180px"
                    :label="item.extendfieldname + '：'"
                  >
                    <el-input
                      v-model.trim="formData1[item.extendfieldname]"
                      @input="onInput2()"
                      @change="changeInput2(item)"
                      v-if="item.fieldtype == '文字'"
                      type="text"
                      maxlength="10"
                      :placeholder="'请填写' + item.extendfieldname"
                    ></el-input>
                    <el-input
                      v-model.trim="formData1[item.extendfieldname]"
                      @input="onInput2()"
                      @change="changeInput2(item)"
                      v-if="item.fieldtype == '数字'"
                      oninput="value=value.replace(/[^\d]/g,'').slice(0,10)"
                      :min="0"
                      type="tel"
                      :placeholder="
                        '请填写' + item.extendfieldname + '（数字类型）'
                      "
                    ></el-input>
                  </el-form-item>
                </div>
              </span>
            </el-form>
            <!--商品资质认证-->
            <el-form-item
              label-width="110px"
              label="商品资质认证"
              style="background: #e1e1e1"
              v-show="categoryTemplateShow"
            >
            </el-form-item>
            <el-form :model="formData4" :rules="form4Rules" ref="formData4">
              <span v-if="categoryTemplate != [] && categoryTemplate != null">
                <h3 style="height: 50px; margin-left: 40px" class="thrTitle">
                  {{ categoryTemplate.name || "" }}
                </h3>
                <div
                  v-for="(item, index) in categoryTemplate.templateItemFormList"
                  :key="item.id"
                >
                  <el-form-item
                    :prop="item.fieldname"
                    label-width="180px"
                    :label="item.fieldname + '：'"
                  >
                    <input type="hidden" v-model="item.fieldvalue" />
                    <el-input
                      v-model="formData4[item.fieldname]"
                      @input="onInput()"
                      @change="changeInput(item)"
                      v-if="item.fieldtype == '文字'"
                      type="text"
                      :placeholder="'请填写' + item.fieldname"
                    ></el-input>
                    <el-input
                      v-model="formData4[item.fieldname]"
                      @input="onInput()"
                      @change="changeInput(item)"
                      v-if="item.fieldtype == '数字'"
                      type="number"
                      :placeholder="'请填写' + item.fieldname"
                    ></el-input>
                    <el-input
                      v-model="formData4[item.fieldname]"
                      v-if="item.fieldtype == '图片'"
                      type="hidden"
                    ></el-input>
                    <el-upload
                      v-if="item.fieldtype == '图片'"
                      :action="uploadUrl"
                      :on-success="
                        (response, file, fileList) =>
                          handleFieldSuccess(
                            response,
                            file,
                            fileList,
                            'formData4',
                            item.fieldname,
                            index
                          )
                      "
                      :on-remove="
                        (file, fileList) =>
                          handleFieldPicRemove(
                            file,
                            fileList,
                            'formData4',
                            'fieldname' + index,
                            index
                          )
                      "
                      :on-change="(file) => handleChange(file)"
                      list-type="picture-card"
                      :show-file-list="false"
                      class="avatar-uploader"
                    >
                      <el-popover
                        v-if="item.fieldvalue"
                        placement="right"
                        trigger="hover"
                      >
                        <img
                          :src="item.fieldvalue"
                          style="width: 400px; border-radius: 3px"
                        />
                        <img
                          slot="reference"
                          :src="item.fieldvalue"
                          class="avatar"
                          style="width: 100%; height: 100%"
                        />
                      </el-popover>
                      <i v-else class="el-icon-plus"></i>
                    </el-upload>
                  </el-form-item>
                </div>
              </span>
            </el-form>
            <!--2-->
            <el-form-item
              label-width="80px"
              label="规格参数"
              style="background: #e1e1e1"
              v-show="categoryTemplateShow"
            >
            </el-form-item>
            <el-form-item>
              <div v-for="(item, index) in inputData" :key="index">
                <el-form-item style="width: 30%">
                  <div style="float: none">
                    <el-tag>{{ item.key }}</el-tag>
                    <el-input
                      v-model="item.val"
                      placeholder="请输入内容"
                      clearable
                      size="small"
                    />
                  </div>
                </el-form-item>
              </div>
            </el-form-item>

            <!--3-->
            <el-form-item
              label-width="55px"
              label="库存"
              style="background: #e1e1e1"
            >
              <span>{{ formData.commoditynum }}</span>
            </el-form-item>

            <el-form-item>
              <el-table
                v-loading="loading"
                :data="parameterlist"
                :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
                border
              >
                <el-table-column label="商品图片" width="100" align="center">
                  <template slot-scope="scope">
                    <el-upload
                      ref="upload"
                      class="avatar-uploader"
                      :data="uploadData1"
                      :action="uploadUrl"
                      :show-file-list="false"
                      :on-success="handleAvatarSuccess"
                      @click.native="curRowIndex = scope.$index"
                    >
                      <img
                        v-if="scope.row.inventorypic"
                        :src="scope.row.inventorypic"
                        class="avatar"
                        style="width: 50px; height: 50px"
                      />
                      <i
                        v-else
                        class="el-icon-plus avatar-uploader-icon"
                        @click="curRowIndex = scope.$index"
                        style="line-height: 2.3"
                      ></i>
                    </el-upload>
                  </template>
                </el-table-column>
                <el-table-column label="规格参数" align="center">
                  <div v-for="(item, index) in inputData" :key="index">
                    <el-table-column
                      :label="item.key"
                      width="150"
                      align="center"
                    >
                      <template slot-scope="scope">
                        <div v-if="scope.row.splist !== undefined">
                          <el-select
                            v-model="scope.row.splist[index]"
                            placeholder="请选择"
                            clearable
                            @change="paramchange($event, scope.$index, item)"
                          >
                            <el-option
                              v-for="(it, ind) in item.val.split(',')"
                              :key="ind"
                              :label="it"
                              :value="it"
                            >
                            </el-option>
                          </el-select>
                        </div>
                      </template>
                    </el-table-column>
                  </div>
                </el-table-column>

                <el-table-column
                  label="成本价"
                  prop="costprice"
                  width="150"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-input-number
                      style="width: 120px"
                      v-model="scope.row.costprice"
                      align="center"
                      @change="costprice(scope.$index, scope.row)"
                      :min="0"
                      :controls="false"
                      :precision="2"
                    ></el-input-number>
                  </template>
                </el-table-column>

                <el-table-column
                  label="经销价"
                  prop="secondaryagentprice"
                  width="150"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-input-number
                      style="width: 120px"
                      v-model="scope.row.secondaryagentprice"
                      align="center"
                      :min="0"
                      :controls="false"
                      :precision="2"
                      @change="secondaryagentprice(scope.$index, scope.row)"
                    ></el-input-number>
                  </template>
                </el-table-column>
                <el-table-column
                  label="分销价"
                  prop="commodityprice"
                  width="150"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-input-number
                      style="width: 120px"
                      v-model="scope.row.commodityprice"
                      align="center"
                      :min="0"
                      :controls="false"
                      :precision="2"
                      @change="commodityprice(scope.$index, scope.row)"
                    ></el-input-number>
                  </template>
                </el-table-column>
                <el-table-column
                  label="零售价"
                  prop="commodityoldprice"
                  width="150"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-input-number
                      style="width: 120px"
                      v-model="scope.row.commodityoldprice"
                      align="center"
                      :min="0"
                      :controls="false"
                      :precision="2"
                      @change="commodityoldprice(scope.$index, scope.row)"
                    ></el-input-number>
                  </template>
                </el-table-column>

                <el-table-column
                  label="推广比例(%)"
                  prop="profitproportion"
                  width="160"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-input-number
                      style="width: 120px"
                      v-model="scope.row.profitproportion"
                      align="center"
                      :min="0"
                      :controls="false"
                      :precision="2"
                      @change="profitproportion(scope.$index, scope.row)"
                    ></el-input-number>
                  </template>
                </el-table-column>

                <el-table-column label="操作" align="center" fixed="right">
                  <template slot-scope="scope">
                    <el-button
                      type="danger"
                      size="mini"
                      @click.native="paraDel(scope.$index, scope.row)"
                      >删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>

              <div align="center" style="margin: 10px">
                <el-button
                  :disabled="formData.thirdcategoryid == ''"
                  type="primary"
                  @click="addpara()"
                  >添加</el-button
                >
              </div>
            </el-form-item>

            <!--3-->
            <el-form-item
              label-width="65px"
              label="轮播图"
              style="background: #e1e1e1"
            >
            </el-form-item>

            <el-form-item style="display: inline-block">
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
              <el-upload
                :action="uploadUrl"
                :on-change="handleChange"
                list-type="picture-card"
                :on-success="handleSuccess"
                :on-remove="handlePicRemove"
                :file-list="uploadData"
                ><i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
            <el-form-item
              label-width="80px"
              label="商品详情"
              style="background: #e1e1e1"
            ></el-form-item>
          </el-form>

          <div>
            <!-- 图片上传组件辅助-->
            <el-upload
              class="edituploader"
              :action="uploadUrl"
              :show-file-list="false"
              :on-success="imguploadSuccess"
              :on-error="uploadError"
              :before-upload="beforeUpload"
            >
            </el-upload>
            <quill-editor
              v-model="formData.commoditydesc"
              ref="myQuillEditor"
              :options="editorOption"
              @change="onEditorChange($event)"
            >
            </quill-editor>
          </div>
        </el-card>
        <div slot="footer" class="dialog-footer">
          <el-button @click.native="hideForm">取消</el-button>
          <el-button
            type="primary"
            @click.native="formSubmit()"
            :loading="formLoading"
            >提交</el-button
          >
        </div>
      </el-dialog>

      <!--库存管理-->
      <el-dialog
        title="库存管理"
        :visible.sync="inventoryVisible"
        :before-close="hideInventoryForm"
        width="50%"
        top="5vh"
        v-dialogDrag
        :close-on-click-modal="false"
      >
        <template slot="title">
          <div class="avue-crud__dialog__header">
            <span class="el-dialog__title">
              <span
                style="
                  display: inline-block;
                  background-color: #3478f5;
                  width: 3px;
                  height: 20px;
                  margin-right: 5px;
                  float: left;
                  margin-top: 2px;
                "
              ></span>
              库存管理
            </span>
            <div class="avue-crud__dialog__menu">
              <icon-svg icon-class="quanping" />
              <span class="mention">双击全屏</span>
            </div>
          </div>
        </template>
        <el-card>
          <el-form :model="formData" label-width="140px">
            <el-form-item
              label-width="80px"
              label="基本参数"
              style="background: #e1e1e1"
            />
            <el-form-item label="商品名称：">
              <span>{{ formData.commodityname }}</span>
              <!-- <input v-model="formData.commodityname" type="text" readonly> -->
            </el-form-item>

            <el-form-item
              label-width="80px"
              label="规格参数"
              style="background: #e1e1e1"
            />
            <el-table
              v-loading="loading"
              :data="parameterlist"
              :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
              border
            >
              <el-table-column
                label="商品图片"
                width="100"
                align="center"
                fixed
              >
                <template slot-scope="scope">
                  <el-popover
                    v-if="scope.row.inventorypic"
                    placement="right"
                    trigger="hover"
                  >
                    <img
                      :src="scope.row.inventorypic"
                      style="width: 400px; border-radius: 3px"
                    />
                    <img
                      slot="reference"
                      :src="scope.row.inventorypic"
                      style="
                        max-height: 80px;
                        max-width: 50px;
                        border-radius: 5px;
                      "
                    />
                  </el-popover>
                  <span v-else>-</span>
                </template>
              </el-table-column>
              <el-table-column label="规格参数" align="center">
                <div v-for="(item, index) in inputData" :key="index">
                  <el-table-column :label="item.key" width="150" align="center">
                    <template slot-scope="scope">
                      <div v-if="scope.row.splist !== undefined">
                        <el-select
                          v-model="scope.row.splist[index]"
                          placeholder="请选择"
                          clearable
                          @change="paramchange($event, scope.$index, item)"
                          disabled
                        >
                          <el-option
                            v-for="(it, ind) in item.val.split(',')"
                            :key="ind"
                            :label="it"
                            :value="it"
                          >
                          </el-option>
                        </el-select>
                      </div>
                    </template>
                  </el-table-column>
                </div>
              </el-table-column>
              <el-table-column label="成本价" prop="costprice" align="center" />
              <el-table-column
                label="经销价"
                prop="secondaryagentprice"
                align="center"
              />
              <el-table-column
                label="分销价"
                prop="commodityprice"
                align="center"
              />
              <el-table-column
                label="零售价"
                prop="commodityoldprice"
                align="center"
              />
              <el-table-column
                label="库存"
                prop="commoditynum"
                width="220"
                align="center"
              >
                <template slot-scope="scope">
                  <el-input-number
                    :min="0"
                    :max="99999"
                    v-model="scope.row.inventorynum"
                    controls-position="right"
                    placeholder="请输入商品库存"
                    clearable
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                label="起购数量"
                prop="buyfromnum"
                width="220"
                align="center"
              >
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.buyfromnum"
                    controls-position="right"
                    placeholder="起购数量"
                    clearable
                    :min="1"
                    :max="99999"
                  ></el-input-number>
                </template>
              </el-table-column>
            </el-table>
          </el-form>
        </el-card>
        <div slot="footer" class="dialog-footer">
          <el-button @click.native="inventoryHideForm()">取消</el-button>
          <el-button
            type="primary"
            @click.native="inventoryFormSubmit()"
            :loading="formLoading"
            :disabled="formLoading"
            >提交</el-button
          >
        </div>
      </el-dialog>
      <!-- 提示窗 -->
      <el-dialog
        title="拒绝原因"
        :visible.sync="rejectVisible"
        width="50%"
        :before-close="handleClose"
        :close-on-click-modal="false"
      >
        <template slot="title">
          <div class="avue-crud__dialog__header">
            <span class="el-dialog__title">
              <span
                style="
                  display: inline-block;
                  background-color: #3478f5;
                  width: 3px;
                  height: 20px;
                  margin-right: 5px;
                  float: left;
                  margin-top: 2px;
                "
              ></span>
              拒绝原因
            </span>
          </div>
        </template>
        <!--列表start --222s-->
        <el-table
          v-loading="rejectloading"
          :data="rejectList"
          :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
          border
        >
          <el-table-column label="招商审核人" prop="userName" align="center" />
          <el-table-column
            label="拒绝原因"
            prop="rejectreason"
            align="center"
          />
          <el-table-column label="拒绝时间" align="center">
            <template slot-scope="scope">
              <i
                class="el-icon-time"
                v-if="scope.row.operationtime != null"
              ></i>
              <span v-if="scope.row.operationtime != null">{{
                scope.row.operationtime | formatDateStr("yyyy-MM-dd hh:mm:ss")
              }}</span>
            </template>
          </el-table-column>
        </el-table>
        <!-- 列表2 -->
        <el-table
          v-loading="rejectpinloading"
          :data="rejectListpin"
          :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
          border
          style="margin-top: 20px"
        >
          <el-table-column label="品控审核人" prop="userName" align="center" />
          <el-table-column
            label="拒绝原因"
            prop="rejectreason"
            align="center"
          />
          <el-table-column label="拒绝时间" align="center">
            <template slot-scope="scope">
              <i
                class="el-icon-time"
                v-if="scope.row.operationtime != null"
              ></i>
              <span v-if="scope.row.operationtime != null">{{
                scope.row.operationtime | formatDateStr("yyyy-MM-dd hh:mm:ss")
              }}</span>
            </template>
          </el-table-column>
        </el-table>
        <!-- <span>{{ rejectreason }}</span> -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="rejectVisible = false">关 闭</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>
<script>
import {
  getList,
  getMainCategoryMap,
  delBusCommodity,
  addBusCommodity,
  updateBusCommodity,
  getGoodsCertificationInfo,
  updateBusCommodityInventoryNum,
  checkAudit, //查看驳回的状态
} from "../../api/buscommodity/buscommodity.js";
import Tinymce from "../../components/Tinymce/index.vue";
import { BASE_URL } from "../../config/app";
import { quillEditor } from "vue-quill-editor"; //调用编辑器
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
import Table from "../../components/Table";
/*用作表单的数据初始化*/
const formJson = {
  attributecontenct: "", //商品基本属性
  attributeextendcontenct: "", //扩展属性
  commodityid: "", //商品id
  commodityname: "", //商品名称
  recommendstatus: 0, //商品'0不推荐1推荐',
  onshelfstatus: 1, //商品 0全部，  1不上架 2上架',
  commodityicon: "", //商品图片
  commodityprice: "", // 售价    decimal(20,2),
  commodityoldprice: "", //商品原价    decimal(20,2),
  commodityfrom: "", // 货源地
  topcategoryname: "", //一级分类
  secondarycategoryname: "", //二级分类
  thirdcategoryname: "", //三级分类
  commoditynum: "", // 库存
  createtime: "", // 添加时间
  commoditydesc: "", //商品描述
  commoditypiclist: [], //图片
  piclist: "", //图片列表
  videopic: "", //视频地址
  topcategoryid: "", //一级分类id',
  secondarycategoryid: "", //二级分类id',
  thirdcategoryid: "", // 三级分类id,
  inids: "", //参数id
  param: "",
  inputdata: "", //全部参数
  certificationcontent: "",
};
const toolbarOptions = [
  ["bold", "italic", "underline", "strike"], // toggled buttons
  [{ header: 1 }, { header: 2 }], // custom button values
  [{ list: "ordered" }, { list: "bullet" }],
  [{ indent: "-1" }, { indent: "+1" }], // outdent/indent
  [{ direction: "rtl" }], // text direction
  [{ size: ["small", false, "large", "huge"] }], // custom dropdown
  [{ header: [1, 2, 3, 4, 5, 6, false] }],
  [{ color: [] }, { background: [] }], // dropdown with defaults from theme
  [{ font: [] }],
  [{ align: [] }],
  ["link", "image"],
  ["clean"],
];
export default {
  components: {
    Tinymce,
    quillEditor,
    Table,
  },
  data() {
    return {
      certificationAuditData: [], //资质审核数据
      certificationAuditOptions: [
        {
          type: "tag",
          prop: "certificationstatus",
          plan: "danger",
          label: "品控审核状态",
          format: (val) => {
            if (val == 0) return "待审核";
            if (val == 1) return "已通过";
            if (val == 2) return "已驳回";
          },
        },

        {
          prop: "rejectreason",
          label: "驳回原因",
          style: { color: "hotpink" },
        },
        { type: "date", prop: "operationtime", label: "审核时间" },
      ], //资质审核表格配置
      goodsAuditData: [], //商品审核数据
      goodsAuditOptions: [
        {
          type: "tag",
          prop: "certificationstatus",
          label: "招商审核状态",
          format: (val) => {
            if (val == 0) return "待审核";
            if (val == 1) return "已通过";
            if (val == 2) return "已驳回";
          },
        },
        { prop: "rejectreason", label: "驳回原因" },
        { type: "date", prop: "operationtime", label: "审核时间" },
      ], //商品审核表格配置
      rejectList: [], //招商驳回列表
      rejectListpin: [], //品控驳回列表
      rejectloading: false, //招商列表loading
      rejectpinloading: false, //品控列表loading
      formData1: {},
      categoryTemplate: [], // 商品类目模板
      attributecontenct: [], //商品属性
      attributeextendcontenct: [], //商品属性模板
      emptyTemplate: [], //空模板
      query: {
        //查询条件
        content: "",
        starttime: "",
        endtime: "",
        onshelfstatus: "0", //0全部，  1不上架 2上架
        recommendstatus: "", //0不推荐1推荐
        currentPage: 1,
        pageSize: 5,
        thirdcategoryid: "", //三级
      },
      formData: formJson, //新增或修改的对象
      commoditypiclist: [],
      formName: "",
      formMap: {
        add: "添加",
        edit: "编辑",
        detail: "查看",
      },
      uploadUrl: BASE_URL + "/goldendays-currency/tool/uploadpro", //上传图片
      uploadvideo: BASE_URL + "/tool/uploadVideo", //上传视频
      uploadData: [], //[{name:"12",url:"http://localhost/maotianxiaupload/common/2019-08-23/MH1566545692219_mid.jpg"}], // 图片data
      vuploadData: [], //视频
      uploadData1: {}, // 图片data
      curRowIndex: 0, //图片row
      createTime: [], //选择日期时需要的model
      list: [], //列表集合
      parameterlist: [], //add参数list
      rejectVisible: false,
      rejectreason: "", //驳回信息
      //savadd参数list
      category: [], //分类列表
      buswarehouse: [], //仓库列表
      busCommoditySecondaryCategoryList: [], //二级
      busCommodityThirdCategoryList: [], //三级
      categoryobj: {}, //分类列表
      oneCategoryObj: {}, //一级
      twoCategoryObj: {}, //二级
      ThirdCategoryobj: {}, //三级
      inputData: [], // 循环创建input存值
      totalNumber: 0, //分页总页数
      formVisible: false, //添加编辑显示
      loading: true, //列表加载
      dis: true, //不可点击
      formLoading: false, //表单提交加载
      allLoding: false, //全屏加载
      cancelToggle: false,
      detailVisible: false, //查看
      classification: false,
      multipleSelection: [], //多选集合
      categoryTemplateShow: true,
      inventoryVisible: false,
      formRules: {
        commodityname: {
          required: true,
          message: "请输入名称",
          trigger: "blur",
        },
        thirdcategoryid: {
          required: true,
          message: "请选择分类",
          trigger: "blur",
        },
        /*commodityprice: {
                      required: true,
                      message: "请输入售价",
                      trigger: "blur",
                    },
                    commodityoldprice: {
                      required: true,
                      message: "请输入代理价",
                      trigger: "blur",
                    },*/
        commoditydesc: {
          required: true,
          message: "请输入商品详情",
          trigger: "blur",
        },
      },
      form1Rules: {},
      form4Rules: {},
      formData4: {
        certificationcontent: null, // 商品分类模板
        topcategoryid: null, // 一级商品分类id
        secondarycategoryid: null, // 二级商品分类id
        categoryid: null, // 三级商品分类id
      },

      quillUpdateImg: false, // 根据图片上传状态来确定是否显示loading动画，刚开始是false,不显示
      // content: null,
      editorOption: {
        placeholder: "",
        theme: "snow", // or 'bubble'
        modules: {
          toolbar: {
            container: toolbarOptions,
            handlers: {
              image: function (value) {
                if (value) {
                  // 触发input框选择图片文件
                  document.querySelector(".edituploader input").click();
                } else {
                  this.quill.format("image", false);
                }
              },
            },
          },
        },
      },
      //serverUrl: '/manager/common/imgUpload', // 这里写你要上传的图片服务器地址
      header: {
        // token: sessionStorage.token
      },
    };
  },
  watch: {},
  methods: {
    costprice(index, row) {
      if (
        row.secondaryagentprice != null &&
        row.secondaryagentprice != "" &&
        row.costprice != null &&
        row.costprice != ""
      ) {
        var secondaryagentprice = row.secondaryagentprice - 0;
        var costprice = row.costprice - 0;
        if (secondaryagentprice < costprice) {
          this.$message.error("成本价不能高于于经销价,请重新输入!");
          row.costprice = "";
          return false;
        }
      }
    },

    secondaryagentprice(index, row) {
      if (
        row.secondaryagentprice != null &&
        row.secondaryagentprice != "" &&
        row.costprice != null &&
        row.costprice != ""
      ) {
        var secondaryagentprice = row.secondaryagentprice - 0;
        var costprice = row.costprice - 0;
        if (secondaryagentprice < costprice) {
          this.$message.error("经销价不能低于成本价,请重新输入!");
          row.costprice = "";
          return false;
        }
      }
      if (
        row.commodityprice != null &&
        row.commodityprice != "" &&
        row.secondaryagentprice != null &&
        row.secondaryagentprice != ""
      ) {
        var commodityprice = row.commodityprice - 0;
        var secondaryagentprice1 = row.secondaryagentprice - 0;
        if (commodityprice < secondaryagentprice1) {
          this.$message.error("经销价不能高于分销价,请重新输入!");
          row.secondaryagentprice = "";
          return false;
        }
      }
    },
    commodityprice(index, row) {
      if (
        row.commodityprice != null &&
        row.commodityprice != "" &&
        row.secondaryagentprice != null &&
        row.secondaryagentprice != ""
      ) {
        var commodityprice = row.commodityprice - 0;
        var secondaryagentprice = row.secondaryagentprice - 0;
        if (commodityprice < secondaryagentprice) {
          this.$message.error("分销价不能低于经销价,请重新输入!");
          row.commodityprice = "";
          return false;
        }
      }
      if (
        row.commodityprice != null &&
        row.commodityprice != "" &&
        row.commodityoldprice != null &&
        row.commodityoldprice != ""
      ) {
        var commodityprice1 = row.commodityprice - 0;
        var commodityoldprice = row.commodityoldprice - 0;
        if (commodityoldprice < commodityprice1) {
          this.$message.error("分销价不能高于零售价,请重新输入!");
          row.commodityprice = "";
          return false;
        }
      }
    },
    commodityoldprice(index, row) {
      if (
        row.commodityprice != null &&
        row.commodityprice != "" &&
        row.commodityoldprice != null &&
        row.commodityoldprice != ""
      ) {
        var commodityprice = row.commodityprice - 0;
        var commodityoldprice = row.commodityoldprice - 0;
        if (commodityoldprice < commodityprice) {
          this.$message.error("零售价不能低于分销价,请重新输入!");
          row.commodityoldprice = "";
          return false;
        }
      }
    },
    profitproportion(index, row) {
      if (row.profitproportion != null && row.profitproportion != "") {
        if (row.profitproportion > 30.0 || row.profitproportion < 1) {
          this.$message.error("推广比例应设置1~30之间!");

          return false;
        }
      }
    },

    //图片上传成功
    handleFieldSuccess(response, file, fileList, index, key, item) {
      if (response.status === 1) {
        this.$set(this[index], key, response.data);

        if (item || item == 0) {
          this.categoryTemplate.templateItemFormList[item].fieldvalue =
            this.formData4[key];
        }
        return;
      }
      this.$message.error("上传文件报错");
    },
    // 移除图片
    handleFieldPicRemove(file, fileList, index, key, item) {
      this[index][key] = null;
      if (item || item == 0) {
        this.categoryTemplate.templateItemFormList[item].fieldvalue = null;
      }
    },
    //图片上传成功
    handleFormDataSuccess(response, file, fileList, index, key, item) {
      if (response.status === 1) {
        this[index][key] = response.data;
        if (item) {
          item.fieldvalue = this.formData4[item.fieldname];
        }
        return;
      }
      this.$message.error("上传文件报错");
    },
    // 强制刷新input
    onInput() {
      this.$forceUpdate();
    },
    // 模板input监听
    changeInput(val) {
      val.fieldvalue = this.formData4[val.fieldname];
    },

    // 商品属性强制刷新input
    onInput1() {
      this.$forceUpdate();
    },
    // 商品属性模板input监听
    changeInput1(val) {
      val.fieldvalue = this.formData1[val.fieldname];
      console.log(val);
    },

    // 商品属性强制刷新input
    onInput2() {
      this.$forceUpdate();
    },
    // 商品属性模板input监听
    changeInput2(val) {
      val.fieldvalue = this.formData1[val.extendfieldname];
      console.log(val);
    },
    getBrandList() {},
    onEditorChange({ editor, html, text }) {
      this.formData.commoditydesc = html;
    },
    // 富文本图片上传前
    beforeUpload() {
      // 显示loading动画
      this.quillUpdateImg = true;
    },

    imguploadSuccess(response, file) {
      let quill = this.$refs.myQuillEditor.quill;

      // 如果上传成功
      if (response.status === 1) {
        let filePath = response.data;
        // 获取光标所在位置
        let length = quill.getSelection().index;
        // 插入图片 res.url为服务器返回的图片地址
        quill.insertEmbed(length, "image", filePath);
        // 调整光标到最后
        quill.setSelection(length + 1);
        this.$message.success("图片插入成功");
      } else {
        this.$message.error("图片插入失败");
      }
      // loading动画消失
      this.quillUpdateImg = false;
    },
    // 富文本图片上传失败
    uploadError() {
      // loading动画消失
      this.quillUpdateImg = false;
      this.$message.error("图片插入失败");
    },
    //table列表参数
    paramchange(e, i, it) {
      for (let j = 0; j < this.parameterlist.length > 0; j++) {
        for (let i = 0; i < this.parameterlist[j].splist.length; i++) {
          if (this.parameterlist[j].splist[i] === e) {
            let data = {};
            this.$set(data, it.key, e);
            this.parameterlist[j].savparameterlist[i] = data;
          }
        }
      }
    },

    arrNumber(arr) {
      var arr_number = {};
      for (var i = 0; i < arr.length; i++) {
        if (arr_number[arr[i]]) {
          arr_number[arr[i]]++;
        } else {
          arr_number[arr[i]] = 1;
        }
      }
      return arr_number;
    },
    formSubmit() {
      // console.log(this.parameterlist);
      let plist = this.parameterlist;
      for (let i = 0; i < plist.length; i++) {
        let jsonval = JSON.stringify(plist[i].savparameterlist);
        let json = plist[i].savparameterlist;
        let indata = {};
        for (var j = 0, l = json.length; j < l; j++) {
          for (var key in json[j]) {
            this.$set(indata, key, json[j][key]);
          }
        }
        plist[i].inventory = JSON.stringify(indata);
        plist[i].secinventory = jsonval;
      }
      this.$refs["formData1"].validate((valid) => {});
      this.$refs["formData4"].validate((valid) => {});
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          if (
            this.formData.commoditypiclist &&
            this.formData.commoditypiclist.length !== 0
          ) {
            this.formData.commodityicon = this.formData.commoditypiclist[0];
            this.formData.piclist = this.formData.commoditypiclist.join(",");
          }
          if (plist.length > 0) {
            let num = 0;
            var inventorylistobj = [];
            for (let i = 0; i < plist.length; i++) {
              let nm = 1;
              inventorylistobj.push(plist[i].inventory);
              var inventory = plist[i].inventory.substring(
                1,
                plist[i].inventory.length - 1
              );
              var inventorylist = inventory.split(":");

              if (inventorylist[1].length < 3) {
                this.$message.warning("请完善商品规格信息！");
                return false;
              }
              if (plist[i].costprice < 1) {
                this.$message.warning("请完善商品规格信息！");
                return false;
              }
              if (plist[i].commodityprice < 1) {
                this.$message.warning("请完善商品规格信息！");
                return false;
              }

              if (plist[i].commodityoldprice < 1) {
                this.$message.warning("请完善商品规格信息！");
                return false;
              }
              if (plist[i].secondaryagentprice < 1) {
                this.$message.warning("请完善商品规格信息！");
                return false;
              }

              if (
                plist[i].profitproportion < 1 ||
                plist[i].profitproportion > 30
              ) {
                this.$message.warning("推广比例应设置1~30之间！");
                return false;
              }
              if (plist[i].profitproportion == undefined) {
                this.$message.warning("推广比例应设置1~30之间!");
                return false;
              }
              num += plist[i].inventorynum * nm;
            }
            //零售价
            this.formData.commodityprice = plist[0].commodityoldprice;
            //经销价
            this.formData.commodityoldprice = plist[0].secondaryagentprice;
            this.formData.commoditynum = num;

            var inventoryojb = this.arrNumber(inventorylistobj);

            for (let i = 0; i < plist.length; i++) {
              var inventorycount = inventoryojb[plist[i].inventory];

              if (inventorycount > 1) {
                this.$message.warning("商品不可添加俩个及以上的相同规格！");
                return false;
              }
            }
          } else {
            this.$message.warning("无商品规格信息！");
            return false;
          }

          this.formData.param = JSON.stringify(plist);
          this.formData.inputdata = JSON.stringify(this.inputData);
          if (
            this.formData.inputdata == null ||
            this.formData.inputdata == ""
          ) {
            this.$message.warning("无规格数据！");
            return false;
          }
          let flag = false;
          var msg = "";
          if (
            this.categoryTemplate == null ||
            this.categoryTemplate == undefined
          ) {
            this.$message.warning("无商品模板！");
            return false;
          }
          //无商品属性模板
          if (
            this.attributecontenct == null ||
            this.attributecontenct == undefined
          ) {
            this.$message.warning("无商品属性模板！");
            return false;
          }
          //赋值商品属性模板
          this.formData.attributecontenct = JSON.stringify(
            this.attributecontenct
          );
          this.formData.attributeextendcontenct = JSON.stringify(
            this.attributeextendcontenct
          );
          //赋值商品模板
          this.formData.certificationcontent = JSON.stringify(
            this.categoryTemplate
          );
          if (
            this.attributecontenct != null &&
            this.attributecontenct != undefined
          ) {
            this.attributecontenct.forEach((item) => {
              if (
                (item.fieldvalue == null || item.fieldvalue == "") &&
                item.ismust == 0
              ) {
                msg = item.fieldname;
                flag = true;
              }
            });
          } else {
            this.$message.warning("无商品属性模板！");
            return false;
          }
          if (flag) {
            this.$message({
              message: msg + "不能为空！",
              type: "warning",
            });
            return false;
          }
          if (
            this.attributeextendcontenct != null &&
            this.attributeextendcontenct != undefined
          ) {
            this.attributeextendcontenct.forEach((item) => {
              if (
                (item.fieldvalue == null || item.fieldvalue == "") &&
                item.ismust == 0
              ) {
                msg = item.extendfieldname;
                flag = true;
              }
            });
          } else {
            this.$message.warning("无商品属性模板！");
            return false;
          }
          if (flag) {
            this.$message({
              message: msg + "不能为空！",
              type: "warning",
            });
            return false;
          }

          if (
            this.categoryTemplate.templateItemFormList != null &&
            this.categoryTemplate.templateItemFormList != undefined
          ) {
            this.categoryTemplate.templateItemFormList.forEach((item) => {
              if (
                (item.fieldvalue == null || item.fieldvalue == "") &&
                item.ismust == 0
              ) {
                msg = item.fieldname;
                flag = true;
              }
            });
          } else {
            this.$message.warning("无商品模板！");
            this.formLoading = false;
            return false;
          }
          if (flag) {
            this.$message({
              message: msg + "不能为空！",
              type: "warning",
            });
            return false;
          }
          var params = new URLSearchParams(this.formData);
          this.formLoading = true;
          addBusCommodity(params)
            .then((response) => {
              if (response.code != 0) {
                this.$message.error(response.message);
                this.formLoading = false;
                return false;
              }
              this.$message.success("操作成功");
              this.uploadData = []; //图片
              this.vuploadData = []; //视频

              this.formData = {};
              // this.$refs.tinymce.setContent("");

              this.formLoading = false;
              this.formVisible = false;

              this.dis = true;
              // 加载表格数据
              this.getList();
              // 清空表单
              this.$refs["ruleForm"].resetFields();
              //取消
              this.closeCategory();
            })
            .catch(() => {
              this.formLoading = false;
              this.formVisible = false;
              this.dis = true;
            });
        }
      });
    },
    inventoryFormSubmit() {
      let plist = this.parameterlist;
      for (let i = 0; i < plist.length; i++) {
        if (plist[i].inventorynum == null || plist[i].inventorynum == "") {
          this.$message.warning("库存不能为空");
          return false;
        }
        if (plist[i].inventorynum < 0 || plist[i].inventorynum == "") {
          this.$message.warning("库存不能小于0");
          return false;
        }
        if (plist[i].buyfromnum == null || plist[i].buyfromnum == "") {
          this.$message.warning("起购不能为空");
          return false;
        }
        if (plist[i].buyfromnum < 1 || plist[i].buyfromnum == "") {
          this.$message.warning("起购不能小于1");
          return false;
        }
        if (plist[i].buyfromnum > plist[i].inventorynum) {
          this.$message.warning("起购不能大于库存，请重新输入");
          return false;
        }
      }
      this.formData.param = JSON.stringify(plist);
      var params = new URLSearchParams(this.formData);

      updateBusCommodityInventoryNum(params)
        .then((response) => {
          this.formLoading = true;
          if (response.code != 0) {
            this.$message.error(response.message);
            return false;
          }
          this.$message.success("操作成功");

          this.formData = {};
          // this.$refs.tinymce.setContent("");

          this.formLoading = false;
          this.inventoryVisible = false;

          this.dis = true;
          // 加载表格数据
          this.getList();
        })
        .catch(() => {
          this.formLoading = false;
          this.inventoryVisible = false;
          this.dis = true;
        });
    },
    /*----------*/
    //列表
    handleAvatarSuccess(response, file) {
      this.isSelect = false;
      if (response.status === 1) {
        const filePath = response.data;

        this.parameterlist[this.curRowIndex].inventorypic = filePath;
        return;
      }
      this.$message.error("上传文件报错");
    },
    // 图片上传
    AvatarUpload(file) {
      this.fileName = file.name ? file.name : "";
      return false;
    },
    //图片上传成功
    vhandleSuccess(response, file) {
      this.isSelect = false;
      if (response.status === 1) {
        const filePath = response.data; //视频地址
        const vPath = response.content; //视频截图地址
        this.formData.videopic = filePath;
        return;
      }

      this.$message.error("上传文件报错");
    },
    // 图片上传
    vhandleChange(file) {
      this.fileName = file.name ? file.name : "";
      return false;
    },
    //图片上传成功
    handleSuccess(response, file) {
      this.isSelect = false;
      if (response.status === 1) {
        const filePath = response.data;
        this.commoditypiclist.push(filePath);
        this.formData.commoditypiclist = this.commoditypiclist;
        return;
      }

      this.$message.error("上传文件报错");
    },
    // 图片上传
    handleChange(file) {
      this.fileName = file.name ? file.name : "";
      return false;
    },
    handlePicRemove(file, fileList) {
      var url = "";
      url = file.url;
      for (var i = 0; i < this.formData.commoditypiclist.length; i++) {
        if (url === this.formData.commoditypiclist[i]) {
          this.formData.commoditypiclist.splice(i, 1);
        }
      }
      for (let i = 0; i < this.uploadData.length; i++) {
        if (url === this.uploadData[i].url) {
          this.uploadData.splice(i, 1);
        }
      }
    },

    //添加参数
    addpara() {
      let param = {
        inventoryid: "", //          bigint not null auto_increment,
        commodityid: "", //          bigint,
        inventory: "", //      规格参数      text,
        secinventory: "", //规格参数2
        commodityprice: 0, //    分销价   decimal(20,2),
        commodityoldprice: 0, //  零售价  decimal(20,2),
        profitproportion: "", //推广比例
        primaryagentprice: 0,
        // primaryagentprice: 0, //一级代理
        secondaryagentprice: 0, //二级代理
        costprice: 0, //成本价
        inventorynum: 0, //      库存   int,
        buyfromnum: 1, //      起购   int,
        inventorypic: "", //   规格图片      varchar(200),
        companytype: 0, //      单位    smallint comment '0:瓶 1箱 2:套',
        boxnum: "", //      每箱瓶数         int comment '每箱瓶数',
        savparameterlist: [],
        splist: [],
      };
      let p = {
        key: "",
        val: "",
      };

      param.savparameterlist.push(p);
      this.parameterlist.push(param);
    },
    //删除
    paraDel(index, row) {
      // console.log(row);
      this.parameterlist.splice(index, 1);
    },
    //关闭分类
    closeCategory() {
      this.classification = false;
      this.formData.topcategoryid = "";
      this.formData.secondarycategoryid = "";
      this.formData.thirdcategoryid = "";

      this.categoryobj = {};
      this.ThirdCategoryobj = {};
      this.inputData = [];
    },
    //add分类
    chosebtn() {
      this.classification = true;
    },
    //查看评论
    lookcomment(v) {
      this.$router.push({
        path: "/merchant/comment",
        query: { cid: v },
      });
      // alert(v)
    },
    //add 隐藏表单
    hideForm() {
      // 更改值
      this.formVisible = !this.formVisible;
      // 清空表单
      this.$refs["ruleForm"].resetFields();
      return true;
    },
    //add 库存管理隐藏表单
    inventoryHideForm() {
      // 更改值
      this.inventoryVisible = !this.inventoryVisible;
      return true;
    },
    /* --------------*/
    //筛选上架
    shelfstatus() {
      if (this.query.onshelfstatus === "0") {
        this.$router.push({
          path: "",
        });
        //刷新事件需要重置查询条件
        this.createTime = [];
        this.query = {
          currentPage: 1,
          pageSize: 10,
        };
        this.getList();
      } else {
        this.query.currentPage = 1;
        this.$router.push({
          path: "",
          query: this.query,
        });
        this.getList();
      }
    },
    //上架
    onshelfschange(row) {
      this.loading = true;
      var params = new URLSearchParams();
      params.append("commodityid", row.commodityid);
      params.append("onshelfstatus", row.onshelfstatus);
      updateBusCommodity(params)
        .then((response) => {
          this.loading = false;
          if (response.code) {
            this.$message.error(response.message);
            return false;
          }
          this.loading = false;
          this.$message.success("更新成功");
          // 刷新数据
        })
        .catch(() => {
          this.loading = false;
        });
    },
    //推荐
    recommendchange(row) {
      this.loading = true;
      var params = new URLSearchParams();
      params.append("commodityid", row.commodityid);
      params.append("recommendstatus", row.recommendstatus);
      updateBusCommodity(params)
        .then((response) => {
          this.loading = false;
          if (response.code) {
            this.$message.error(response.message);
            return false;
          }
          this.loading = false;
          this.$message.success("更新成功");
          // 刷新数据
        })
        .catch(() => {
          this.loading = false;
        });
    },
    // 显示表单
    handleForm() {
      this.categoryTemplate = [];
      this.attributecontenct = [];
      this.attributeextendcontenct = [];
      this.formVisible = true;
      this.formName = "add";
      this.inputData = [];
      this.parameterlist = [];
      this.uploadData = [];
      this.commoditypiclist = [];
      this.formData.commoditypiclist = [];
      this.categoryTemplateShow = false;
      this.uploadData = [];
      this.formData = {
        attributecontenct: "",
        attributeextendcontenct: "",
        commodityid: "", //商品id
        commodityname: "", //商品名称
        recommendstatus: 0, //商品'0不推荐1推荐',
        onshelfstatus: 1, //商品 0全部，  1不上架 2上架',
        commodityicon: "", //商品图片
        commodityprice: "", // 售价    decimal(20,2),
        profitproportion: "",
        commodityoldprice: "", //商品原价    decimal(20,2),
        commodityfrom: "", // 货源地
        topcategoryname: "", //一级分类
        secondarycategoryname: "", //二级分类
        thirdcategoryname: "", //三级分类
        primaryentitybillie: "",
        seniorentitybillie: "",
        commoditytype: "",
        commoditynum: "", // 库存
        createtime: "", // 添加时间
        commoditydesc: "", //商品描述
        commoditypiclist: [], //图片
        piclist: "", //图片列表
        videopic: "", //视频地址
        topcategoryid: "", //一级分类id',
        secondarycategoryid: "", //二级分类id',
        thirdcategoryid: "", // 三级分类id,

        inids: "", //参数id
        param: "",
        inputdata: "", //全部参数
      };
    },
    //调取驳回原因接口
    checkAudit(query) {
      checkAudit(query)
        .then((res) => {
          if (res.code != 0) {
            this.$message.error(res.message);
            return false;
          }
          this.goodsAuditData = res.data.canvassList;
          this.certificationAuditData = res.data.qualityList;
        })
        .catch((err) => {
          this.$message.error(err);
          return false;
        });
    },
    //显示 查看弹框
    detailForm(index, row) {
      let query = {};
      query.commodityid = row.commodityid;
      query.operationtype = 0;
      this.checkAudit(query);
      this.detailVisible = true;
      this.attributecontenct = [];
      this.attributeextendcontenct = [];
      if (row !== null) {
        this.inputData = [];
        console.log(row);
        this.formData = Object.assign({}, row);

        this.formData.secondarycategoryid = row.secondarycategoryid;
        this.formData.thirdcategoryid = row.thirdcategoryid;
        //处理商品属性模板
        if (row.attributecontenct != null) {
          this.attributecontenct = JSON.parse(row.attributecontenct);
          this.formData.attributecontenct = JSON.parse(row.attributecontenct);
          if (
            this.attributecontenct != null &&
            this.attributecontenct != undefined
          ) {
            this.attributecontenct.forEach((item) => {
              this.formData1[item.fieldname] = item.fieldvalue;
            });
          }
        }
        if (row.attributeextendcontenct != null) {
          this.attributeextendcontenct = JSON.parse(
            row.attributeextendcontenct
          );
          this.formData.attributeextendcontenct = JSON.parse(
            row.attributeextendcontenct
          );
          if (
            this.attributeextendcontenct != null &&
            this.attributeextendcontenct != undefined
          ) {
            this.attributeextendcontenct.forEach((item) => {
              this.formData1[item.extendfieldname] = item.fieldvalue;
            });
          }
        }
        //处理商品模板数据
        if (row.certificationcontent != null) {
          this.categoryTemplate = JSON.parse(row.certificationcontent);
          this.formData.certificationcontent = JSON.parse(
            row.certificationcontent
          );
          if (
            this.categoryTemplate.templateItemFormList != null &&
            this.categoryTemplate.templateItemFormList != undefined
          ) {
            this.categoryTemplate.templateItemFormList.forEach((item) => {
              this.formData4[item.fieldname] = item.fieldvalue;
            });
          }
        }
        if (
          row.inventorylist != null &&
          row.inventorylist[0].inputdata != null
        ) {
          this.inputData = JSON.parse(row.inventorylist[0].inputdata);
        } else {
          let data = {
            key: "",
            val: "",
          };
          this.inputData.push(data);
        }
      }
      let data = [];
      let pic = [];
      let vdata = [];
      let vpic = [];
      for (let i = 0; i < row.commoditypiclist.length; i++) {
        let picdata = row.commoditypiclist[i];
        if (picdata.recoursetype === 0) {
          let obj = {
            name: "",
            url: "",
          };
          obj.name = i;
          obj.url = picdata.picurl;
          data.push(obj);
          pic.push(picdata.picurl);
        }
        if (picdata.recoursetype === 1) {
          let obj = {
            name: "",
            url: "",
          };
          obj.name = i;
          obj.url = picdata.picurl;
          vdata.push(obj);
          vpic.push(picdata.picurl);
        }
      }
      this.formData.videopic = vpic;
      this.vuploadData = vdata;
      this.commoditypiclist = pic;
      this.formData.commoditypiclist = pic;
      this.uploadData = data;

      this.parameterlist = row.inventorylist;
      for (let i = 0; i < this.parameterlist.length; i++) {
        let sav = [];
        this.$set(this.parameterlist[i], "savparameterlist", sav);
        this.$set(this.parameterlist[i], "splist", sav);
        // let arr = this.parameterlist[0].inputdata
        // console.log(arr)
        var a = this.parameterlist[i].inventory.indexOf("}");
        var b = this.parameterlist[i].inventory.substring(1, a);
        var a1 = b.split(",");
        var splist1 = [];
        for (let c = 0; c < a1.length; c++) {
          var s = a1[c]
            .split(":")[1]
            .substring(1, a1[c].split(":")[1].length - 1);
          splist1.push(s);
        }
        //县域百分比回显
        if (this.parameterlist[i].profitproportion < 1) {
          this.parameterlist[i].profitproportion *= 100;
        } else {
          this.parameterlist[i].profitproportion;
        }
        this.parameterlist[i].splist = splist1;
        this.parameterlist[i].savparameterlist = JSON.parse(
          this.parameterlist[i].secinventory
        );
        this.parameterlist[i].companytype =
          this.parameterlist[i].companytype.toString();
      }
      //参数
      let sav = [];
      if (this.parameterlist != null && this.parameterlist.length > 0) {
        for (let i = 0; i < this.parameterlist.length; i++) {
          let pdata = JSON.parse(this.parameterlist[i].secinventory);
          for (let i = 0; i < pdata.length; i++) {
            let mdata = pdata[i];
            for (let v in mdata) {
              sav.push(mdata[v].toString());
            }
          }
          this.parameterlist.savparameterlist = pdata;
        }
        this.parameterlist.splist = sav;
      }
      this.formName = "detail";
    },

    // 隐藏详情弹框
    hideDetailForm() {
      // 更改值
      this.detailVisible = !this.detailVisible;
      return true;
    },
    // 隐藏库存管理
    hideInventoryForm() {
      // 更改值
      this.inventoryVisible = !this.inventoryVisible;
      return true;
    },
    hideclassification() {
      this.classification = !this.classification;
      return true;
    },

    //编辑
    editForm(index, row) {
      console.log(row);
      this.formVisible = true;
      this.categoryTemplateShow = true;
      this.formData = Object.assign({}, formJson);
      //商品属性模板处理
      if (row.attributecontenct != null) {
        let ss = Object.assign({}, row);
        this.attributecontenct = JSON.parse(ss.attributecontenct);
        this.formData.attributecontenct = JSON.parse(row.attributecontenct);
        if (
          this.attributecontenct != null &&
          this.attributecontenct != undefined
        ) {
          this.attributecontenct.forEach((item) => {
            this.formData1[item.fieldname] = item.fieldvalue;
          });
        } else {
          this.categoryTemplateShow = false;
        }
      } else {
        this.attributecontenct = this.emptyTemplate;
      }
      //扩展属性模板
      if (row.attributeextendcontenct != null) {
        let ss = Object.assign({}, row);
        this.attributeextendcontenct = JSON.parse(ss.attributeextendcontenct);
        this.formData.attributeextendcontenct = JSON.parse(
          row.attributeextendcontenct
        );
        if (
          this.attributeextendcontenct != null &&
          this.attributeextendcontenct != undefined
        ) {
          this.attributeextendcontenct.forEach((item) => {
            this.formData1[item.extendfieldname] = item.fieldvalue;
          });
        } else {
          this.categoryTemplateShow = false;
        }
      } else {
        this.attributeextendcontenct = this.emptyTemplate;
      }

      //数据处理商品模板
      if (row.certificationcontent != null) {
        var ss = Object.assign({}, row);
        this.categoryTemplate = JSON.parse(ss.certificationcontent);
        this.formData.certificationcontent = JSON.parse(
          row.certificationcontent
        );
        if (
          this.categoryTemplate.templateItemFormList != null &&
          this.categoryTemplate.templateItemFormList != undefined
        ) {
          this.categoryTemplate.templateItemFormList.forEach((item) => {
            this.formData4[item.fieldname] = item.fieldvalue;
          });
        } else {
          this.categoryTemplateShow = false;
        }
      } else {
        this.categoryTemplate = this.emptyTemplate;
      }
      if (row !== null) {
        this.inputData = [];
        this.formData = Object.assign({}, row);

        if (
          row.inventorylist != null &&
          row.inventorylist[0].inputdata != null
        ) {
          this.inputData = JSON.parse(row.inventorylist[0].inputdata);
        } else {
          let data = {
            key: "",
            val: "",
          };
          this.inputData.push(data);
        }
      }
      let data = [];
      let pic = [];
      let vdata = [];
      let vpic = [];
      for (let i = 0; i < row.commoditypiclist.length; i++) {
        let picdata = row.commoditypiclist[i];
        if (picdata.recoursetype === 0) {
          let obj = {
            name: "",
            url: "",
          };
          obj.name = i;
          obj.url = picdata.picurl;
          data.push(obj);
          pic.push(picdata.picurl);
        }
        if (picdata.recoursetype === 1) {
          let obj = {
            name: "",
            url: "",
          };
          obj.name = i;
          obj.url = picdata.picurl;
          vdata.push(obj);
          vpic.push(picdata.picurl);
        }
      }

      this.formData.videopic = vpic;
      this.vuploadData = vdata;
      this.commoditypiclist = pic;
      this.formData.commoditypiclist = pic;
      this.uploadData = data;
      this.parameterlist = row.inventorylist;
      for (let i = 0; i < this.parameterlist.length; i++) {
        let sav = [];
        this.$set(this.parameterlist[i], "savparameterlist", sav);
        this.$set(this.parameterlist[i], "splist", sav);
        var a = this.parameterlist[i].inventory.indexOf("}");
        var b = this.parameterlist[i].inventory.substring(1, a);
        var a1 = b.split(",");
        var splist1 = [];
        for (let c = 0; c < a1.length; c++) {
          var s = a1[c]
            .split(":")[1]
            .substring(1, a1[c].split(":")[1].length - 1);
          splist1.push(s);
        }
        //县域百分比回显
        if (this.parameterlist[i].profitproportion < 1) {
          this.parameterlist[i].profitproportion *= 100;
        } else {
          this.parameterlist[i].profitproportion;
        }
        this.parameterlist[i].splist = splist1;
        this.parameterlist[i].savparameterlist = JSON.parse(
          this.parameterlist[i].secinventory
        );

        this.parameterlist[i].companytype =
          this.parameterlist[i].companytype.toString();
      }
      //参数
      let sav = [];
      if (this.parameterlist != null && this.parameterlist.length > 0) {
        for (let i = 0; i < this.parameterlist.length; i++) {
          let pdata = JSON.parse(this.parameterlist[i].secinventory);

          for (let i = 0; i < pdata.length; i++) {
            let mdata = pdata[i];
            for (let v in mdata) {
              sav.push(mdata[v].toString());
            }
          }
          this.parameterlist.savparameterlist = pdata;
        }
        this.parameterlist.splist = sav;
      }

      this.formName = "edit";
      /*三级*/
      for (var k = 0; k < this.busCommodityThirdCategoryList.length; k++) {
        if (
          this.busCommodityThirdCategoryList[k].thirdcategoryid ==
          this.formData.thirdcategoryid
        ) {
          this.ThirdCategoryobj = this.busCommodityThirdCategoryList[k];

          this.formData.thirdcategoryname =
            this.busCommodityThirdCategoryList[k].thirdcategoryname;

          break;
        }
      }
    },
    //库存管理
    editInventoryForm(index, row) {
      this.inventoryVisible = true;
      this.formData = Object.assign({}, formJson);
      if (row !== null) {
        this.inputData = [];
        this.formData = Object.assign({}, row);

        if (
          row.inventorylist != null &&
          row.inventorylist[0].inputdata != null
        ) {
          this.inputData = JSON.parse(row.inventorylist[0].inputdata);
        } else {
          let data = {
            key: "",
            val: "",
          };
          this.inputData.push(data);
        }
      }
      let data = [];
      let pic = [];
      let vdata = [];
      let vpic = [];
      for (let i = 0; i < row.commoditypiclist.length; i++) {
        let picdata = row.commoditypiclist[i];
        if (picdata.recoursetype === 0) {
          let obj = {
            name: "",
            url: "",
          };
          obj.name = i;
          obj.url = picdata.picurl;
          data.push(obj);
          pic.push(picdata.picurl);
        }
        if (picdata.recoursetype === 1) {
          let obj = {
            name: "",
            url: "",
          };
          obj.name = i;
          obj.url = picdata.picurl;
          vdata.push(obj);
          vpic.push(picdata.picurl);
        }
      }

      this.formData.videopic = vpic;
      this.vuploadData = vdata;
      this.commoditypiclist = pic;
      this.formData.commoditypiclist = pic;
      this.uploadData = data;
      this.parameterlist = row.inventorylist;
      for (let i = 0; i < this.parameterlist.length; i++) {
        let sav = [];
        this.$set(this.parameterlist[i], "savparameterlist", sav);
        this.$set(this.parameterlist[i], "splist", sav);
        var a = this.parameterlist[i].inventory.indexOf("}");
        var b = this.parameterlist[i].inventory.substring(1, a);
        var a1 = b.split(",");
        var splist1 = [];
        for (let c = 0; c < a1.length; c++) {
          var s = a1[c]
            .split(":")[1]
            .substring(1, a1[c].split(":")[1].length - 1);
          splist1.push(s);
        }
        this.parameterlist[i].splist = splist1;
        this.parameterlist[i].savparameterlist = JSON.parse(
          this.parameterlist[i].secinventory
        );

        this.parameterlist[i].companytype =
          this.parameterlist[i].companytype.toString();
      }
      //参数
      let sav = [];
      if (this.parameterlist != null && this.parameterlist.length > 0) {
        for (let i = 0; i < this.parameterlist.length; i++) {
          let pdata = JSON.parse(this.parameterlist[i].secinventory);
          for (let i = 0; i < pdata.length; i++) {
            let mdata = pdata[i];
            for (let v in mdata) {
              sav.push(mdata[v].toString());
            }
          }
          this.parameterlist.savparameterlist = pdata;
        }
        this.parameterlist.splist = sav;
      }
    },

    /*获取列表事件*/
    getList() {
      this.loading = true;
      this.list = [];
      getList(this.query)
        .then((response) => {
          if (response.code != 0) {
            this.$message.error(response.message);
            return false;
          }
          this.list = response.data.list || [];

          this.totalNumber = response.data.totalNumber || 0;
          setTimeout(() => {
            this.loading = false;
          }, 0.3 * 1000);
        })
        .catch(() => {
          this.loading = false;
          this.list = [];
        });
    },
    thirdchange(type) {
      if (type == 1) {
        this.onSubmit();
      }
      if (type == 2) {
        for (var i = 0; i < this.busCommodityThirdCategoryList.length; i++) {
          if (
            this.busCommodityThirdCategoryList[i].topcategoryid ==
            this.formData.thirdcategoryid
          ) {
            this.ThirdCategoryobj = this.busCommodityThirdCategoryList[i];
            if (this.ThirdCategoryobj.specification != null) {
              let data = this.ThirdCategoryobj.specification.split(",");
              let indata = [];
              for (let i = 0; i < data.length; i++) {
                let mydata = {
                  key: "",
                  val: "",
                };
                mydata.key = data[i];
                mydata.val = "";
                indata.push(mydata);
              }
              this.inputData = indata;
            } else {
              this.inputData = [];
            }
            this.formData.thirdcategoryname =
              this.busCommodityThirdCategoryList[i].thirdcategoryname;
            this.classification = false;
            break;
          }
        }
        if (this.formData.thirdcategoryid == "") {
          return;
        }
        this.getTemplate(this.formData.thirdcategoryid); //传递三级目录的id获取商品资质认证的模板
      }
    },
    //传递三级目录的id获取商品属性和商品资质认证的模板
    getTemplate(thirdcategoryid) {
      this.categoryTemplateShow = false;
      this.categoryTemplate = [];
      this.attributecontenct = [];
      this.attributeextendcontenct = [];
      const formData = new FormData();
      formData.append("threeCategoryId", thirdcategoryid);

      getGoodsCertificationInfo(formData)
        .then((response) => {
          if (response.code) {
            this.$message.error(response.message);
            this.loading = false;
          }
          console.log(response.data);
          this.categoryTemplate = response.data;
          this.attributecontenct = response.data.attributesTemplateItemList;
          this.attributeextendcontenct =
            response.data.extendAttributesTemplateItemList;
          if (
            this.categoryTemplate != null &&
            this.categoryTemplate.templateItemFormList != undefined
          ) {
            this.categoryTemplateShow = true;
            this.categoryTemplate.templateItemFormList.forEach((item) => {
              this.$set(this.formData4, item.fieldname, null);
              if (item.ismust == 0) {
                if (item.fieldtype == "图片") {
                  this.$set(this.form4Rules, item.fieldname, {
                    required: true,
                    message: `${item.fieldname}为必填项`,
                    trigger: "change",
                  });
                } else {
                  this.$set(this.form4Rules, item.fieldname, {
                    required: true,
                    message: `${item.fieldname}为必填项`,
                    trigger: "blur",
                  });
                }
              }
            });
          }
          if (this.attributecontenct != null) {
            this.categoryTemplateShow = true;
            this.attributecontenct.forEach((item) => {
              // this.formData1[item.fieldname] = null;
              this.$set(this.formData1, item.fieldname, null);
              if (item.ismust == 0) {
                this.$set(this.form1Rules, item.fieldname, {
                  required: true,
                  message: `${item.fieldname}为必填项`,
                  trigger: "blur",
                });
              }
            });
          }
          if (this.attributeextendcontenct != null) {
            this.categoryTemplateShow = true;
            this.attributeextendcontenct.forEach((item) => {
              // this.formData1[item.extendfieldname] = null;
              this.$set(this.formData1, item.extendfieldname, null);
              if (item.ismust == 0) {
                this.$set(this.form1Rules, item.extendfieldname, {
                  required: true,
                  message: `${item.extendfieldname}为必填项`,
                  trigger: "blur",
                });
              }
            });
          }
        })
        .catch((err) => {
          this.$message.error(err);
          this.loading = false;
        });
    },
    //获得分类
    getAllCategory() {
      this.loading = true;
      getMainCategoryMap()
        .then((response) => {
          if (response.code) {
            this.$message.error(response.message);
          }
          this.oneCategoryObj = response.data.one || {};
          this.twoCategoryObj = response.data.two || {};
          this.busCommodityThirdCategoryList = response.data.threeList || [];
          setTimeout(() => {
            this.loading = false;
          }, 0.3 * 1000);
        })
        .catch(() => {
          this.loading = false;
          this.list = [];
          this.totalNumber = 0;
        });
    },
    /*日期选择事件*/
    dateChange(val) {
      if (val == null) {
        this.query.starttime = "";
        this.query.endtime = "";
      } else {
        this.query.starttime = val[0];
        this.query.endtime = val[1];
        this.query.currentPage = 1;
      }
      this.getList();
    },
    /*列表查询条件事件*/
    onSubmit() {
      this.query.currentPage = 1;
      this.getList();
    },

    /*刷新*/
    onRest() {
      //刷新事件需要重置查询条件
      this.createTime = [];
      this.query = {
        currentPage: 1,
        pageSize: 5,
      };
      this.getList();
    },

    /*点击页数*/
    handleCurrentChange(val) {
      this.query.currentPage = val;
      this.getList();
    },

    /*选择每页条数【10,20,30,40,50】*/
    handleSizeChange(val) {
      this.query.pageSize = val;
      this.getList();
    },

    /*取消全选事件*/
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },

    /*列表复选框选择事件*/
    handleSelectionChange(val) {
      this.multipleSelection = val;
      if (val == "") {
        this.cancelToggle = false;
        return;
      }
      this.cancelToggle = true;
    },

    /*全选删除事件*/
    delGroup() {
      var ids = this.multipleSelection.map((item) => item.commodityid).join(); //获取所有选中行的id组成的字符串，以逗号分隔
      if (ids == "") {
        this.$message({
          message: "请先选择",
          type: "warning",
        });
        return;
      }
      this.handleDel(ids);
    },
    onchange() {
      this.$forceUpdate();
    },
    /*选中事件*/
    handleDel(ids) {
      if (ids) {
        this.$confirm("确认要删除吗?", "提示", {
          type: "warning",
        })
          .then(() => {
            this.loading = true;
            var params = new URLSearchParams();
            params.append("ids", ids);
            delBusCommodity(params)
              .then((response) => {
                this.loading = false;
                if (response.code) {
                  this.$message.error(response.message);
                  return false;
                }
                this.$message.success("删除成功");
                // 刷新数据
                //this.list.splice(index, 1);
                this.getList();
              })
              .catch(() => {
                this.loading = false;
              });
          })
          .catch(() => {
            this.$message.warning("已取消");
          });
      }
    },
    //调取驳回原因接口
    checkpAudit(query) {
      checkAudit(query)
        .then((res) => {
          this.rejectloading = true;
          this.rejectpinloading = true;
          if (res.code != 0) {
            this.$message.error(res.message);
            setTimeout(() => {
              this.rejectpinloading = false;
              this.rejectloading = false;
            }, 0.3 * 1000);
            return false;
          }
          this.rejectList = res.data.canvassList;
          this.rejectListpin = res.data.qualityList;
          setTimeout(() => {
            this.rejectpinloading = false;
            this.rejectloading = false;
          }, 0.3 * 1000);
        })
        .catch((err) => {
          this.$message.error(err);
          return false;
        });
    },
    openAlert(row) {
      this.rejectVisible = true;
      let query = {};
      query.commodityid = row.commodityid;
      query.operationtype = row.commoditystatus;
      this.checkpAudit(query);
    },
    handleClose() {
      this.rejectreason = "";
      this.rejectVisible = false;
    },
  },

  created() {
    this.getList();
    this.getAllCategory();
  },
};
</script>
<style type="text/css">
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 21px;
  color: #8c939d;
  width: 50px;
  height: 50px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
